package com.ubxtech.jdk21.service.impl;

import cn.hutool.core.util.StrUtil;
import com.ubxtech.core.context.ContextToken;
import com.ubxtech.core.context.ContextUtil;
import com.ubxtech.web.handler.auth.LoginCustomAuthService;
import com.ubxtech.web.utils.WebUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * @author Victor.Xiao
 * @since 2024-03-26 16:06
 **/
@Service
public class LoginCustomAuthServiceImpl implements LoginCustomAuthService {
    @Override
    public boolean auth(HttpServletRequest request, HttpServletResponse response, Object handler) {
        String token = WebUtil.getHeader(request, "token");
        String query = request.getQueryString();
        System.out.println(query);
        ContextToken contextToken = new ContextToken();
        contextToken.setUserId("1");
        contextToken.setTenant("1");
        contextToken.setToken(token);

        contextToken.setTenantMulti(Set.of("1","2"));
        ContextUtil.setContextToken(contextToken);

        if (StrUtil.isNotBlank(token)) {
            return true;
        }
        return false;
    }
}
